home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / rbsetnv1.zip / DELPATH.C < prev    next >
Text File  |  1990-04-13  |  1KB  |  57 lines

  1. /*
  2.  * delpath.c
  3.  *
  4.  * Returned status:
  5.  *    0    OK (including case where nothing needs to be done)
  6.  *    1    bad arguments
  7.  *
  8.  */
  9. #include <io.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12.  
  13. void exit(int status) { _exit(status); }
  14.  
  15. #define writes(s,i)  write(i,s,strlen(s));
  16.  
  17. main(int argc, char *argv[])
  18. {
  19.     int len;
  20.     char *path, *pathname, *str;
  21.  
  22.     if( argc != 2)    {
  23.         writes("Usage: delpath pathname\n",2);
  24.         exit(1);
  25.     } else {
  26.         pathname = strupr(argv[1]);
  27.         len = strlen(pathname);
  28.         /* strip off a trailing ";" and upper-case */
  29.         if( *(pathname+len-1) == ';') *(pathname+len-1) = '\0';
  30.         path = getenv("PATH");
  31.         str = strupr(path);
  32.         while (str)    {
  33.             str = strstr(str, pathname);
  34.             if(!str)    {
  35.                 /* not present in path - nothing to do */
  36.                 writes(path,1);
  37.                 break;
  38.             } else if (*(str+len) == ';')    {
  39.                 /* appears at middle - write out the two parts */
  40.                 *str = '\0';
  41.                 writes(path,1);
  42.                 writes(str+len+1,1);
  43.                 break;
  44.             } else if (*(str+len) == '\0')    {
  45.                 /* appears at end - truncate */
  46.                 *(str-1) = '\0';
  47.                 writes(path,1);
  48.                 break;
  49.             } else    {
  50.                 /* incorrect match found - keep looking */
  51.                 str += len;
  52.             }
  53.         }
  54.     }
  55.     return(0);
  56. }
  57.